home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12983 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Does C convert float to double internally ?
  5. Date: 3 Apr 1996 19:08:20 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4juib4$ivv@news.xs4all.nl>
  8. References: <4jsllh$hkf@harbinger.cc.monash.edu.au>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. bcheung@yoyo.cc.monash.edu.au (Biggles Cheung) writes:
  13.  
  14. >I was told that C compiler automatically converts "float" variable
  15. >internally to "double" for + - * / , etc operations. Is this true?
  16.  
  17. The original K&R said so, but since K&R2 (and ANSI C) compilers
  18. are allowed to use single-precision-only calculations when both
  19. operands and the result are floats.  It entirely depends on
  20. your compiler and the hardware it's running on what the program
  21. will do.
  22.  
  23. >Can I force the C compiler not to do the conversion as I have an
  24. >assignment on finding out various computing errors of different
  25. >precisions? 
  26.  
  27. >My advice from the lecturer is to have temporary variable of
  28. >float to split a long equation to smaller step so that I can maximize
  29. >the impact of single precision number on the evaluation. Is this
  30. >feasible?
  31.  
  32. Yes, you can use a temporary to force some subexpression to 
  33. single precision.  When you store a value in a float, you
  34. are guaranteed to get exactly single precision; this is often
  35. a 32-bit IEEE754 value, but of course your compiler may choose
  36. another representation.
  37.  
  38. Frank
  39. --
  40. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  41. ------------------------------------------------------------------------
  42. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  43.